<template>
  <t-dialog
    header="评审判定"
    :visible.sync="visible"
    :onClose="closeDialog"
    :closeOnOverlayClick="false"
    @confirm="onSubmit"
    :confirmBtn="{
        content: loading?'提交中...':'确认',
        theme: 'primary',
        loading: loading,
      }"
    width="800px"
    top="5%"
  >
   <div style="height: 65vh">
     <t-form ref="form" :colon="true" :data="formData" labelWidth="100px" :rules="rules">
       <t-form-item label="成果名称">
         {{projectName}}
       </t-form-item>
       <t-form-item label="评审类型" name="reviewType">
<!--         <t-select style="width: 390px" disabled  placeholder="评审业务类型" clearable filterable :options="dict.type.wcx_review_type"-->
<!--                   v-model="formData.reviewType">-->
<!--         </t-select>-->
         {{ formData.reviewType | filterByDict(dict.type.wcx_review_type) }}
       </t-form-item>
       <t-form-item label="评审平均分">
         {{formData.sumScore}}
       </t-form-item>
       <t-form-item label="备注" name="content">
         <t-textarea
           clearable :autosize="{minRows: 5}"
           v-model="formData.content"
           placeholder="请输入内容"
         />
       </t-form-item>
       <t-form-item label="是否通过" name="projectStatus" >
         <t-radio-group v-model="formData.projectStatus">
           <t-radio value="1"> 是</t-radio>
           <t-radio value="0"> 否</t-radio>
         </t-radio-group>
       </t-form-item>
     </t-form>
   </div>
  </t-dialog>
</template>

<script>
export default {
  name: "innovation-approval",
  dicts: ['sys_normal_disable', 'subject_classification', 'wcx_review_type'],
  props:["objId","innovationId", "projectName", "reviewType"],
  data(){
    return {
      visible: true,
      loading: false,
      projectStatusOptions:[],
      formData:{
        id:this.objId,
        projectStatus:'1',
        businessId: this.innovationId,
        content: '',
        reviewType: this.reviewType,
      },
      rules:{
        content: [
          { required: true, message: "评审意见不能为空"}
        ],
        projectStatus: [
          { required: true, message: "是否通过不能为空"}
        ],
      }
    }
  },
  created() {
    // 获取评审信息
    this.$api.wcx.review.innovationReviewTeamGet(this.objId).then(response=>{
      if(response.data){
        Object.assign(this.formData, response.data)
        this.formData.projectStatus = response.data.projectStatus || '1';
      }
    }).catch((e) => {
      this.$message.error(e.toString());
    });

  },
  methods:{
    closeDialog() {
      this.$emit("update:visible", false);
    },
    onSubmit() {
      this.$refs.form.validate().then((validateResult) => {
        if (validateResult === true) {
          this.loading = true;
          this.$api.wcx.review.teamInnovationReviewUpdate(this.formData).then(reponse=>{
            this.$message.success("提交成功");
            this.$emit("reload");
            this.$emit("update:visible", false);
            this.loading = false;
          }).catch((e) => {
            this.loading = false;
            this.$message.error(e.toString());
          });
        }else {
          const firstError = Object.values(validateResult)[0]?.[0]?.message;
          this.$message.error(firstError);
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
